package com.bdth.bdthcms.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.bdth.bdthcms.entity.User;
import com.bdth.bdthcms.entity.Userop;
import com.bdth.bdthcms.service.UseropService;
import com.bdth.bdthcms.vo.MessageResult;
import com.bdth.bdthcms.vo.PageVo;
import com.bdth.bdthcms.vo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 用户操作表 前端控制器
 * </p>
 *
 * @author LGP
 * @since 2019-08-27
 */
@Controller
@RequestMapping("/userop")
public class UseropController extends BaseController{
    @Autowired
    private UseropService useropService;

    @RequestMapping("index")
    public String index(){
        return "userop/index";
    }

    @RequestMapping("search")
    public String search(){
        return "userop/search";
    }

    @RequestMapping("form")
    public String form(){
        return "userop/form";
    }

    @RequestMapping(value = "list")
    @ResponseBody
    public PageVo<Userop> getPageList(HttpServletRequest request, Pagination<Userop> pagination,
                                      @RequestParam(required = false) String start,
                                      @RequestParam(required = false) String stop){
        Map<String ,Object> query = new HashMap<>();
        //查询条件
        if(start!=null && !start.equals(""))
            query.put("start",start);
        if(stop!=null && !stop.equals(""))
            query.put("stop",stop);
        User session = (User)request.getSession().getAttribute("loginUser");
        if(session.getGroupid()!=0){
            return null;
        }
        Page<Userop> items = useropService.listPages(pagination, query);
        PageVo<Userop> pageVo = new PageVo<>(items.getRecords(),items.getTotal());
        return pageVo;
    }
}

